<template>
  <el-container class="container">
    <el-header>
      <div class="logo">
        <img alt="logo" src="../assets/logo_qh.png">
      </div>
      <el-menu
        class="nav"
        mode="horizontal"
        :default-active="mainActiveIndex"
        background-color="#545c64"
        text-color="#fff"
        active-text-color="#ffd04b"
        style="margin-left: 200px"
        @select="handleSelect"
      >
        <el-menu-item index="1">
          <router-link to="/main/workOrder/workOrderList/1">工单管理</router-link>
        </el-menu-item>
        <el-menu-item index="2">
          <router-link to="/main/resource/dataCenterList">资源管理</router-link>
        </el-menu-item>
        <el-menu-item index="3">
          <router-link to="/main/operation">运维管理</router-link>
        </el-menu-item>
        <el-menu-item index="4">
          <router-link to="/main/stock">库存管理</router-link>
        </el-menu-item>
        <el-menu-item index="5">
          <router-link to="/main/statement">资源报表</router-link>
        </el-menu-item>
        <el-menu-item index="6">
          <router-link to="/main/system">系统管理</router-link>
        </el-menu-item>
      </el-menu>
      <el-dropdown @command="handleCommand">
        <span>管理员</span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="changePassword">修改密码</el-dropdown-item>
          <el-dropdown-item command="logout">退出</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </el-header>
    <el-container>
      <router-view></router-view>
    </el-container>
  </el-container>
</template>

<script>
import { Message } from 'element-ui'
import { logout } from '../api/userCenterApi'
import Cookies from 'js-cookie'

export default {
  name: 'Main',
  data() {
    return {
      mainActiveIndex: ''
    }
  },
  methods: {
    handleSelect(index) {
      this.mainActiveIndex = index
      sessionStorage.setItem('mainActiveIndex', index)
    },
    handleCommand(command) {
      if (command === 'changePassword') {
        Message.info('changePassword')
      } else {
        this.logout()
      }
    },
    logout() {
      logout()
      Cookies.remove('TOKEN_KEY')
      sessionStorage.clear()
      window.location.href = '/'
    }
  },
  created() {
    let temp = sessionStorage.getItem('mainActiveIndex')
    this.mainActiveIndex = temp ? temp : '1'
  }
}
</script>

<style lang="scss" scoped>
.container {
  min-width: 1300px;
  .el-header {
    padding: 0;
    .logo {
      float: left;
      background-color: rgb(84, 92, 100);
      width: 200px;
      height: 100%;
      img {
        margin-top: 10px;
        height: 40px;
      }
    }
    .nav {
      position: static;
      min-width: 1100px;
      .el-menu-item {
        border-bottom: 0;
        text-align: center;
        padding: 0;
      }
    }
    .el-dropdown {
      position: absolute;
      top: 0;
      right: 50px;
      span {
        display: inline-block;
        height: 40px;
        width: 100px;
        line-height: 40px;
        margin-top: 10px;
        color: #fff;
        cursor: pointer;
      }
    }
    a {
      display: inline-block;
      text-decoration: none;
      height: 60px;
      padding: 0 20px;
    }
  }
}
</style>
